import java.util.Scanner;

/**
 * 二维数组操作
 *
 */
public class HJ83 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int m = scanner.nextInt();
            int n = scanner.nextInt();
            int r1 = scanner.nextInt();
            int c1 = scanner.nextInt();
            int r2 = scanner.nextInt();
            int c2 = scanner.nextInt();
            int r0 = scanner.nextInt();
            int c0 = scanner.nextInt();
            int r = scanner.nextInt();
            int c = scanner.nextInt();

            if(m>0 && m<=9 && n>0 && n<=9){
                System.out.println(0);
            }else {
                System.out.println(-1);
            }
            if(r1<m && c1<n && r2<m && c2 <n){
                System.out.println(0);
            }else {
                System.out.println(-1);
            }
            if(r0<m && m<9){
                System.out.println(0);
            }else {
                System.out.println(-1);
            }
            if(c0<n && n<9){
                System.out.println(0);
            }else {
                System.out.println(-1);
            }

            if(r<m && c<n){
                System.out.println(0);
            }else {
                System.out.println(-1);
            }
        }
    }
}
